package fr.umlv.m2.jee.spij.persistence.education;

import fr.umlv.m2.jee.spij.persistence.actor.StudentRemedial;
import fr.umlv.m2.jee.spij.persistence.actor.TeacherRemedial;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity Remedial who contain information about remedial.
 *
 * @author Lounes Akroune
 * @author Aurelien Scelles
 */
@Entity
@Table(name = "REM_REMEDIAL")
public class Remedial extends Exam {

    /**
     * Primary key.
     */
    @Id
    @Column(name = "REM_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     * Remedial's date.
     */
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @Column(name = "REM_DATE")
    private DateTime date;

    /**
     * Consultation's date.
     */
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @Column(name = "REM_CONSULTATION")
    private DateTime consultation;

    /**
     * Id of linked unit.
     */
    @Column(name = "REM_UNI_ID")
    private Long unit;


    /**
     * List of students.
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "SR_REMEDIAL_ID", referencedColumnName = "REM_ID")
    private List<StudentRemedial> students = new ArrayList<StudentRemedial>();

    /**
     * List of teachers.
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "TR_REMEDIAL_ID", referencedColumnName = "REM_ID")
    private List<TeacherRemedial> teachers = new ArrayList<TeacherRemedial>();

    /**
     * Setter of date.
     *
     * @param newDate the new date to set.
     */
    public final void setDate(final DateTime newDate) {
        this.date = newDate;
    }

    /**
     * Getter of date.
     *
     * @return remedial's date
     */
    public final DateTime getDate() {
        return date;
    }

    /**
     * Setter of consultation.
     *
     * @param newConsultation the consultation date.
     */
    public final void setConsultation(final DateTime newConsultation) {
        this.consultation = newConsultation;
    }

    /**
     * Getter of consultation.
     *
     * @return consultation's date.
     */
    public final DateTime getConsultation() {
        return consultation;
    }

    /**
     * Setter of Id.
     *
     * @param newId the new id.
     */
    public final void setId(final long newId) {
        this.id = newId;
    }

    /**
     * Getter of Id.
     *
     * @return the primary key.
     */
    public final long getId() {
        return id;
    }

    /**
     * Setter of unit.
     *
     * @param newUnit the new unit id to set.
     */
    public final void setUnit(final Long newUnit) {
        this.unit = newUnit;
    }

    /**
     * Getter of unit.
     *
     * @return id of linked unit
     */
    public final Long getUnit() {
        return unit;
    }

    public void setStudents(List<StudentRemedial> students) {
        this.students = students;
    }

    public List<StudentRemedial> getStudents() {
        return students;
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addStudent(StudentRemedial arg0) {
        return students.add(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public StudentRemedial getStudent(int arg0) {
        return students.get(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeStudent(Object arg0) {
        return students.remove(arg0);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfStudents() {
        return students.size();
    }

    public void setTeachers(List<TeacherRemedial> teachers) {
        this.teachers = teachers;
    }

    public List<TeacherRemedial> getTeachers() {
        return teachers;
    }

    /**
     * @param e
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addTeacher(TeacherRemedial e) {
        return teachers.add(e);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public TeacherRemedial getTeacher(int index) {
        return teachers.get(index);
    }

    /**
     * @param o
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeTeacher(Object o) {
        return teachers.remove(o);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfTeachers() {
        return teachers.size();
    }
}
